package com.example.basecommon.view.swipe_refresh;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.basecommon.R;

public class SimpleFooterView extends BaseFooterView {

    private TextView mText;

    private ProgressBar progressBar;
    private boolean hideprogress = false;

    public SimpleFooterView(Context context) {
        this(context, null);
    }

    public SimpleFooterView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleFooterView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        setLayoutParams(new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        View view = LayoutInflater.from(getContext()).inflate(R.layout.pda_layout_footer_view, this);
        progressBar = (ProgressBar) view.findViewById(R.id.footer_view_progressbar);
        mText = (TextView) view.findViewById(R.id.footer_view_tv);
    }

    public void hideProgress(){
        hideprogress = true;
        progressBar.setVisibility(View.GONE);
    }


    @Override
    public void onLoadingMore() {
        progressBar.setVisibility(VISIBLE);
        mText.setVisibility(GONE);
    }

    public void showText(CharSequence message) {
        progressBar.setVisibility(GONE);
        mText.setText(message);
        mText.setVisibility(VISIBLE);
    }

    /**************
     * 文字自行修改或根据传入的参数动态修改
     ****************/

    @Override
    public void onNoMore(CharSequence message) {
        showText(message);
    }

    @Override
    public void onError(CharSequence message) {
        showText(message);
    }

    @Override
    public void onPullTip(CharSequence message) {
        showText(message);
    }

    @Override
    public void onNetChange(boolean isAvailable) {
        if(isAvailable == false){
            showText("网络异常");
        }else{
            showText("网络回复正常");
        }
    }
}
